package chpt05;

import java.util.ArrayList;
import java.util.Scanner;

interface IntegerStack {
	public Integer push(Integer item);
	public Integer pop();
	public Integer peek();
	public boolean empty();
	public int size();
}
public class ArrayListIntegerStack implements IntegerStack {
	private ArrayList<Integer> list;

	public ArrayListIntegerStack() {
		list = new ArrayList<Integer>();
	}

	@Override
	public Integer push(Integer item) {
		if (item == null)
			return null;
		list.add(item);
		return item;
	}

	@Override
	public Integer pop() {
		if (list.isEmpty())
			return null;
		return list.remove(list.size() - 1);
	}

	@Override
	public Integer peek() {
		if (list.isEmpty())
			return null;
		return list.get(list.size() - 1);
	}

	@Override
	public boolean empty() {
		if (list.isEmpty())
			return true;
		return false;
	}

	@Override
	public int size() {
		return list.size();
	}

	@Override
	public String toString() {
		return ""+list;
	}
	
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		IntegerStack stack=new ArrayListIntegerStack();
		int m=in.nextInt();
		for (int i = 0; i < m; i++) {
			System.out.println(stack.push(in.nextInt()));
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(stack.toString());
		int x=in.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(stack.pop());
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(stack.toString());
		in.close();
	}


}


